﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Platformer1
{
  class Obama : CustomEnemy
  {
    public double deathTime = 0;
    public Obama(Level level, Vector2 in_position)
            : base()
        {
            this.Level = level;

            LoadEnemy();

            Position = in_position;
            Reset(Position);
        }
        new public void LoadEnemy()
        {
            idleAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Narwhal/obama"), 0.1f, true);
            runAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Narwhal/obama"), 0.1f, true);
            jumpAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Narwhal/obama"), 0.1f, false);
            dieAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Narwhal/obama"), 0.1f, false);
            punchAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Narwhal/obama"), 0.1f, true);
            jumpPunchAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Narwhal/obama"), 0.1f, true);
            kickAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Narwhal/obama"), 0.1f, true);
            jumpKickAnimation = new Animation(Level.Content.Load<Texture2D>("Sprites/Narwhal/obama"), 0.1f, true);
            hudFont = Level.Content.Load<SpriteFont>("Fonts/Hud");
            debug = Level.Content.Load<Texture2D>("debug");
            int width = (int)(idleAnimation.FrameWidth * 0.4);
            int left = (idleAnimation.FrameWidth - width) / 2;
            int height = (int)(idleAnimation.FrameWidth * 0.8);
            int top = idleAnimation.FrameHeight - height;
            localBounds = new Rectangle(left, top, width, height);

            LoadSoundEffects();

            MoveAcceleration = 7000.0f;
            MaxMoveSpeed = 1000.0f;

            ai_style = 0;
        }

        protected virtual void HandleCollisions()
        {
          // Get the player's bounding rectangle and find neighboring tiles.
          Rectangle bounds = BoundingRectangle;
          int leftTile = (int)Math.Floor((float)bounds.Left / Tile.Width);
          int rightTile = (int)Math.Ceiling(((float)bounds.Right / Tile.Width)) - 1;
          int topTile = (int)Math.Floor((float)bounds.Top / Tile.Height);
          int bottomTile = (int)Math.Ceiling(((float)bounds.Bottom / Tile.Height)) - 1;

          // For each potentially colliding tile,
          for (int y = topTile; y <= bottomTile; ++y)
          {
            for (int x = leftTile; x <= rightTile; ++x)
            {
              // If this tile is collidable,
              TileCollision collision = Level.GetCollision(x, y);
              if (collision != TileCollision.Passable)
              {
                
                // Determine collision depth (with direction) and magnitude.
                Rectangle tileBounds = Level.GetBounds(x, y);
                Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, tileBounds);
                if (depth != Vector2.Zero)
                {
                  float absDepthX = Math.Abs(depth.X);
                  float absDepthY = Math.Abs(depth.Y);

                  // Resolve the collision along the shallow axis.
                  if (absDepthY < absDepthX || collision == TileCollision.Platform)
                  {
                    bloodExplosion();
                  }
                }
              }
            }
          }

          // Save the new bounds bottom.
          previousBottom = bounds.Bottom;
        }
  }
}
